<?php
/**
 * 描述：交易频道-供应商列表。
 * @final
 */
final class Exec_Transaction_Account_List extends Exec
{
    public function Get()
    {
        #绑定数据-经营模式
        View::Assign('Transaction_AccountList_Model',DAO_BusinessModel::GetData());		
		
        #获取参数
        $type=Functions::UrlArgs('type');

        #定义标量
        $data=NULL;
        $params=array();

        #执行程序
        switch($type)
        {
            case 'integrity':
                $data=$this->Get_Integrity();
                $params=array('type'=>'integrity');
            break;
            default:
                echo 'error';
        }

        #处理数据
        foreach($data['Record'] as $index=>&$row)
        {
            //经营模式
            $row['Model']=DAO_BusinessModel::GetName($row['Model']);
            //资质证书
            $row['Licence']=DB::PGetRows('select * from licence where Account=? order by Datetime asc',array($row['Username']));
            //是否诚信供应商
            $row['IsIntegrity']=NULL;
            {
                $tmp=DB::PGetRows('select * from account_integrity where Account=? order by Datetime asc',array($row['Username']));
                if($tmp){
                    $row['IsIntegrity']='TRUE';
                }
                else{
                    $row['IsIntegrity']='FALSE';
                }

            }
            //产品数量
            $row['SupplyAmount']=NULL;
            {
                $tmp=DB::PGetRows('select count(*) as SUPPLYAMOUNT from supply where Account=? order by Datetime asc',array($row['Username']));
                if($tmp){
                    $row['SupplyAmount']=$tmp[0]['SUPPLYAMOUNT'];
                }
                else{
                    $row['SupplyAmount']=0;
                }
            }
        }

        #渲染输出
        View::Assign('Suppliers',$data['Record']);
        View::Assign('PageMenu',PagerFactory::Create('Common')->Fetch($data,array('URL'=>'/exec.php?action=transaction_account_list','IsDetail'=>TRUE,'Parameters'=>$params)));
        View::Display('transaction/account/list.tpl');
    }

    /**
     * 描述：诚信供应商。
     * @access private
     */
    private function Get_Integrity()
    {
        $sql='select * from account ';
        $sql=$sql.'where not exists(select * from account_locked where account.Username=account_locked.Account) ';                      //不锁定
        $sql=$sql.'and not exists(select * from account_delete where account.Username=account_delete.Account) ';                        //没删除
        $sql=$sql.'and exists(select * from account_email_verification where account.Username=account_email_verification.Account) ';    //己通过邮件验证
        $sql=$sql.'and exists(select * from account_integrity where account.Username=account_integrity.Account) ';                      //己通过诚信供应商
        $sql=$sql.'order by Datetime desc limit ?,20';
        $data=DB::GetData($sql);
        return $data;
    }
}
?>